package com.ansatsing.juc.executor.scenario3;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(1);
        for(int i=0;i<4;i++){
            Task task = new Task("name"+i);
            scheduledExecutor.schedule(task,(i+1), TimeUnit.SECONDS);
        }
        scheduledExecutor.shutdown();
        try {
            scheduledExecutor.awaitTermination(1,TimeUnit.DAYS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.printf("Main: Ends at: %s",new Date());
    }
}
